<?php


namespace app\admin\controller;


use app\admin\validate\AdminUser;
use think\facade\View;
use app\admin\business\adminBus;

class Login extends AdminBase
{
    public function index(){
        if($this->isLogin()){
            return redirect(url("index/index"));
        }
        return View::fetch();
    }
    public function loginCheck(){
        $username =$this->request->param('username','');
        $password = $this->request->param('password','');
        $adminData = [
            'name' => $username,
            'password' => $password,
        ];
        $validate = new AdminUser();
        if($validate->check($adminData)){
            return show(config('status.error'),$validate->getError());
        }
        try {
            $adminBus = new adminBus();
            $result = $adminBus->loginBus($adminData);
        } catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        if($result){
            return show(config('status.success'),'登录成功');
        }
        return show(config('status.error'),'登录失败');
    }
}
